// 引入样式
require("../../assets/css/normalize.css");
require("../../assets/css/reset.css");
require("../../assets/fontst/iconfont.css");
require("../../assets/fonts/iconfont.css");
require("./sports_course_detail.less");
// 引入模块
let dom = require("../../utils/dom.js");
let axios = require("../../utils/axios");

document.addEventListener("DOMContentLoaded", function () {
	// 返回按钮
	dom.get(".back").addEventListener("click", function () {
		history.back();
	});
	// 获取地址栏传递的参数id
	let id = location.search.split("=").pop();
	dom.get(".play").addEventListener("click", function () {
		dom.get("#video").play();
	});
	axios.get("/api/train/courseDetail?id=" + id).then((res) => {
		// 将视屏数据储存到localStorage中
		let data = res.data.data.fragments;
		let data2 = res.data.data;
		localStorage.setItem("fragments", JSON.stringify(data));
		let num = 0;
		if (id - 2 < 0) {
			num = 0;
		} else {
			num = id - 2;
		}
		// 1渲染视屏
		dom.get("#video").src = axios.defaults.baseURL + data[num].videoUrl;
		// 视频播放
		dom.get("#end").addEventListener("click", function () {
			video.play();
			this.style.display = "none";
			dom.get("#plays").style.display = "block";
		});
		// 视频暂停
		dom.get("#plays").addEventListener("click", function () {
			video.pause();
			this.style.display = "none";
			dom.get("#end").style.display = "block";
		});
		// 渲染标题
		dom.get("#title").textContent = data[num].title;
		// 渲染运动数据
		dom.get("#calorie").textContent = data2.calorie; //千卡
		dom.get("#time").textContent = data2.time; //时长
		dom.get("#peoplenum").textContent = data2.peoplenum; // 观看人数
	});
});
